﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace XTeam.Core.Helper
{
    public class ConsoleTextWrite : System.IO.TextWriter
    {
        public override Encoding Encoding
        {
            get { return Encoding.UTF8; }
        }

        public event Action<string> OnWriteEvent;

        public override void Write(string value)
        {
            if (this.OnWriteEvent != null)
            {
                this.OnWriteEvent(value);
            }
        }

        public override void WriteLine()
        {
            if (this.OnWriteEvent != null)
            {
                this.OnWriteEvent(Environment.NewLine);
            }
        }

        public override void WriteLine(string value)
        {
            if (this.OnWriteEvent != null)
            {
                this.OnWriteEvent(string.Format("{0}{1}", value, Environment.NewLine));
            }
        }
    }
}
